package com.ssy.lingxi.purchase.controller.purchase;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.request.CommonIdRequest;
import com.ssy.lingxi.purchase.model.request.*;
import com.ssy.lingxi.purchase.model.response.*;
import com.ssy.lingxi.purchase.service.IPurchaseRequisitionService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 采购能力-采购请购单相关接口
 * @author wyx
 * @version 2.0.0
 * @date 2021-10-27
 */
@RestController
@RequestMapping("/purchase/requisition")
public class PurchaseRequisitionController extends BaseController {
    @Resource
    private IPurchaseRequisitionService purchaseRequisitionService;


    /**
     * 请购单-分页查询
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    private Wrapper<PageData<RequisitionPageRes>> getPage(@Valid RequisitionPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getPage(loginUser, req);
    }

    /**
     * 待新增请购单-分页查询
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/create/page", method = RequestMethod.GET)
    private Wrapper<PageData<RequisitionPageRes>> getCreatePage(@Valid RequisitionPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getCreatePage(loginUser, req);
    }

    /**
     * 待审核请购单(一级)-分页查询
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/first/audit/page", method = RequestMethod.GET)
    private Wrapper<PageData<RequisitionPageRes>> getFirstAuditPage(@Valid RequisitionPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getFirstAuditPage(loginUser, req);
    }

    /**
     * 待审核请购单(二级)-分页查询
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/two/audit/page", method = RequestMethod.GET)
    private Wrapper<PageData<RequisitionPageRes>> getTwoAuditPage(@Valid RequisitionPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getTwoAuditPage(loginUser, req);
    }

    /**
     * 待提交请购单-分页查询
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/submit/page", method = RequestMethod.GET)
    Wrapper<PageData<RequisitionPageRes>> getSubmitPage(@Valid RequisitionPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getSubmitPage(loginUser, req);
    }

    /**
     * 创建请购单
     * @param req 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    private Wrapper<Void> create(@RequestBody @Valid RequisitionReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.create(loginUser, req);
    }

    /**
     * 修改请购单
     * @param req 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    private Wrapper<Void> update(@RequestBody @Valid RequisitionUpdateReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.update(loginUser, req);
    }

    /**
     * 查看请购单详情
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<RequisitionDetailRes> getDetail(@Valid CommonIdRequest req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getDetail(loginUser, req);
    }

    /**
     * 删除请购单
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Wrapper<Void> delete(@RequestBody @Valid CommonIdRequest req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.delete(loginUser, req);
    }

    /**
     * 中止请购单
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/pause", method = RequestMethod.POST)
    public Wrapper<RequisitionDetailRes> pause(@RequestBody @Valid RequisitionInnerStatusReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.pause(loginUser, req);
    }

    /**
     * 取消请购单
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/cancel", method = RequestMethod.POST)
    public Wrapper<RequisitionDetailRes> cancel(@RequestBody @Valid RequisitionInnerStatusReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.cancel(loginUser, req);
    }

    /**
     * 待新增请购单-提交审核
     * @param req 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/submit/audit", method = RequestMethod.POST)
    public Wrapper<Void> submitAudit(@RequestBody @Valid CommonIdRequest req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.submitAudit(loginUser, req);
    }

    /**
     * 待审核请购单一级-审核
     * @param req 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/first/audit", method = RequestMethod.POST)
    public Wrapper<Void> firstAudit(@RequestBody @Valid RequisitionAuditReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.firstAudit(loginUser, req);
    }

    /**
     * 待审核请购单二级-审核
     * @param req 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/two/audit", method = RequestMethod.POST)
    public Wrapper<Void> twoAudit(@RequestBody @Valid RequisitionAuditReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.twoAudit(loginUser, req);
    }

    /**
     * 待提交请购单-提交
     * @param req 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public Wrapper<Void> submit(@RequestBody @Valid CommonIdRequest req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.submit(loginUser, req);
    }

    /**
     * 查询请购单内部状态枚举值
     * @return 查询结果
     */
    @RequestMapping(value = "/find/inner/status/enum", method = RequestMethod.GET)
    public Wrapper<List<RequisitionInnerStatusEnumRes>> findInnerStatusEnum() {
        return purchaseRequisitionService.findInnerStatusEnum();
    }

    /**
     * 待请购单转采购订单-分页查询
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/transfer/purchase/page", method = RequestMethod.GET)
    Wrapper<PageData<RequisitionPageRes>> getTransferPurchasePage(@Valid RequisitionPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getTransferPurchasePage(loginUser, req);
    }

    /**
     * 转采购订单-查看详情
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/transfer/purchase/detail", method = RequestMethod.GET)
    public Wrapper<TransferPurchaseDetailRes> getTransferPurchaseDetail(@Valid CommonIdRequest req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getTransferPurchaseDetail(loginUser, req);
    }

    /**
     * 新增请购单订单-选择采购物料列表
     * @param req 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/purchase/order/material/page", method = RequestMethod.GET)
    public Wrapper<PageData<MaterialPageRes>> getPurchaseOrderMaterialPage(@Valid MaterialPageReq req) {
        UserLoginCacheDTO loginUser = this.getSysUser();
        return purchaseRequisitionService.getOrderPurchaseMaterialPage(loginUser, req);
    }

    /**
     * 查询配送方式枚举
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/delivery/method/items", method = RequestMethod.GET)
    public Wrapper<PurchaseDeliveryTypeItemRes> getDeliveryMethodItems(@RequestHeader HttpHeaders headers) {
        return purchaseRequisitionService.getDeliveryMethodItems(headers);
    }
}
